﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for NhaCungCap
/// </summary>
public class NhaCungCap
{
	public NhaCungCap()
	{
	
	}
    public DataTable layNhaCungCap()
    {
        try
        {
            string sql = "select * from NhaCungCap ";
            return DataProvider.GetData(sql);
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }

    public ENhaCungCap layNhaCungCap(string MaNhaCC)
    {
        try
        {
            DataTable tableNhaCC = DataProvider.GetData("Select * from NhaCungCap Where MaNhaCC=@MaNhaCC", "@MaNhaCC", MaNhaCC);
            ENhaCungCap NhaCungCap = new ENhaCungCap();
            NhaCungCap.MaNhaCC = Int32.Parse(tableNhaCC.Rows[0]["MaNhaCC"].ToString());
            NhaCungCap.TenNhaCC = tableNhaCC.Rows[0]["TenNhaCC"].ToString();
            NhaCungCap.DiaChi = tableNhaCC.Rows[0]["DiaChi"].ToString();
            NhaCungCap.DienThoai = tableNhaCC.Rows[0]["DienThoai"].ToString();

            return NhaCungCap;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public bool InsertNhaCungCap(ENhaCungCap NhaCC)
    {
        try
        {
            DataProvider.ExecuteNonQuery("INSERT INTO NhaCungCap VAlUES(@MaNhaCC,@TenNhaCC,@DiaChi,@DienThoai)",
                 "@MaNhaCC", NhaCC.MaNhaCC, "@TenNhaCC", NhaCC.TenNhaCC, "@DiaChi", NhaCC.DiaChi, "@DienThoai", NhaCC.DienThoai);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public bool DeleteNhaCungCap(string MaNhaCC)
    {
        try
        {
            DataProvider.ExecuteNonQuery("DELETE FROM NhaCungCap WHERE MaNhaCC=@MaNhaCC", "@MaNhaCC", MaNhaCC);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public bool UpdateNhaCungCap(ENhaCungCap NhaCC)
    {
        try
        {
            DataProvider.ExecuteNonQuery("Update NhaCungCap set TenNhaCC=@TenNhaCC,DiaChi=@DiaChi,DienThoai=@DienThoai WHERE MaNhaCC=@MaNhaCC", "@TenNhaCC", NhaCC.TenNhaCC, "@DiaChi", NhaCC.DiaChi, "@DienThoai", NhaCC.DienThoai, "@MaNhaCC", NhaCC.MaNhaCC);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    //Hanh
    public bool InsertNhaCungCapH(ENhaCungCap NhaCC)
    {
        try
        {
            DataProvider.ExecuteNonQuery("INSERT INTO NhaCungCap VAlUES(@TenNhaCC,@DiaChi,@DienThoai)", "@TenNhaCC", NhaCC.TenNhaCC, "@DiaChi", NhaCC.DiaChi, "@DienThoai", NhaCC.DienThoai);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public bool UpdateNhaCungCapH(ENhaCungCap NhaCC)
    {
        try
        {
            DataProvider.ExecuteNonQuery("Update NhaCungCap set TenNhaCC=@TenNhaCC,DiaChi=@DiaChi,DienThoai=@DienThoai WHERE MaNhaCC=@MaNhaCC", "@TenNhaCC", NhaCC.TenNhaCC, "@DiaChi", NhaCC.DiaChi, "@DienThoai", NhaCC.DienThoai, "@MaNhaCC", NhaCC.MaNhaCC);
            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

}